import api from '../../api';
import { message } from 'antd';
import { isZiGuanEvir } from '../../utils/commonFunc';

export default {
  namespace: 'etfProposalM',
  state: {},

  effects: {
    //提交etf建议书
    *addEtfProposal({ payload, callback }, { call, put }) {
      let withMAAT = false;
      let response;
      // 判断当前环境是不是资管
      let temp = isZiGuanEvir();
      if (!!temp && temp['iv-user']) withMAAT = true;
      if (withMAAT) {
        response = yield call(api.etfProposal.addEtfProposalWITHMAAT, payload);
      } else {
        response = yield call(api.etfProposal.addEtfProposal, payload);
      }
      if (response && response.success) {
        callback(true);
        message.success('建议书创建成功');
      } else {
        callback();
        message.error(response.message || '建议书创建失败!');
      }
    },

    //获取用户信息
    *getUserInfo({ payload, callback }, { call, put }) {
      const response = yield call(api.user.queryCurrent, payload);
      if (response) {
        callback(response.data);
      }
    },

    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
